import { GaRegExp, CharHandle, ruleInjectable } from "../InjectionRule";

@ruleInjectable()
export default class stringRule extends GaRegExp {

	public RuleInit() {
		this.ParseRule(["\"", this.Supply("STRING"), "(!", this.charHandle, "*)\""]);
	}

	private charHandle: CharHandle = (save, origin, rule, str, index, char, length) => {
		const ruleInfo = rule.info;
		if (ruleInfo.saveStr === "\\") {
			ruleInfo.saveStr = undefined;
			return true;
		} else if (char === "\"") {
			return false;
		} else if (char === "\\") {
			ruleInfo.saveStr = "\\";
			return "next";
		} else if (char === "\n") {
			return false;
		} else {
			return true;
		}
	}

}
